#include <stdio.h>
#include <stdlib.h>
#include "stack_queue.h"

void sqs_init(sq_stack *stack){
    stack->top = -1;
}

int sqs_push(sq_stack *stack, int data){
    if(stack->top == MAX_SIZE -1){
        printf("stack full\n");
        return -1;
    }

    stack->top++;
    stack->data[stack->top] = data;

    return 0;
}

int sqs_pop(sq_stack *stack, int *data){
    if(stack->top <= -1){
        printf("stack is empty\n");
        return -1;
    }

    *data = stack->data[stack->top];
    stack->top--;

    return 0;
}

int ls_init(lslist *list){
    lsnode * new = (lsnode *)malloc(sizeof(lsnode));
    if(new == NULL){
        perror("malloc");
        return -1;
    }

    new->next = NULL;
    *list = new;
    return 0;
}

int ls_push(lslist *list, int data){
    lsnode *new = (lsnode *)malloc(sizeof(lsnode));
    if(new == NULL){
        perror("malloc");
        return -1;
    }

    new->data = data;
    new->next = (*list)->next;
    (*list)->next = new;

    return 0;
}

int ls_pop(lslist *list, int *data){
    if((*list)->next == NULL){
        printf("stack is empty\n");
        return -1;
    }

    lsnode * top = (*list)->next;

    *data = top->data;
    (*list)->next = top->next;
    free(top);

    return 0;
}